package com.zlsy.thread.threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * @author zhouliang
 * @date 2020/7/4 14:18
 */
public class AwaitTerminationThreadPool {
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        for (int i = 0; i < 100; i++) {
            executorService.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName());
                }
            });
        }
        executorService.shutdown();

        try {
            //等待五秒之后查看线程是否已经停止
            boolean isAwaitTermination = executorService.awaitTermination(5, TimeUnit.SECONDS);
            System.out.println(isAwaitTermination);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
